//
//  SettingViewController.m
//  MyProject
//
//  Created by Pei on 16/6/21.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "SettingViewController.h"
#import "UserInfo.h"

@interface SettingViewController ()

@end

@implementation SettingViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [[NSNotificationCenter defaultCenter] postNotificationName:Hide_TabBar_Notification object:nil];
}

- (void)viewDidLoad {
    
    self.navTitle = @"设置";
    
    [super viewDidLoad];
    
    UIImageView *headerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02logo"]];
    headerImageView.frame = CGRectMake((kDeviceWidth-639.0f/3.0f)/2.0f, 40.0f, 639.0f/3.0f, 428.0f/3.0f);
    [self.view addSubview:headerImageView];
    
    UIView *topLine = [[UIView alloc] init];
    topLine.frame = CGRectMake(0.0f, headerImageView.bottom+20.0f, kDeviceWidth, 0.5f);
    topLine.backgroundColor = kGreenColor;
    [self.view addSubview:topLine];
    
    UILabel *versionLbl = [[UILabel alloc] init];
    versionLbl.frame = CGRectMake(10.0f, topLine.bottom+(40.0f-Home_Small_Size)/2.0f, 100.0f, Home_Small_Size);
    versionLbl.text = @"版本信息";
    versionLbl.font = kAppFont(Home_Small_Size);
    versionLbl.textColor = kGreenColor;
    [self.view addSubview:versionLbl];
    
    //kAppVersion
    UILabel *versionValueLbl = [[UILabel alloc] init];
    versionValueLbl.frame = CGRectMake(kDeviceWidth-10.0f-40.0f, versionLbl.origin.y, 40.0f, Home_Small_Size);
    versionValueLbl.text = [NSString stringWithFormat:@"V%@", kAppVersion];
    versionValueLbl.font = kAppFont(Home_Small_Size);
    versionValueLbl.textColor = kGreenColor;
    versionValueLbl.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:versionValueLbl];

    
    UIView *bottomLine = [[UIView alloc] init];
    bottomLine.frame = CGRectMake(0.0f, topLine.bottom+40.0f, kDeviceWidth, 0.5f);
    bottomLine.backgroundColor = kGreenColor;
    [self.view addSubview:bottomLine];
    
    UIButton *logoutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    logoutBtn.frame = CGRectMake(20.0f, bottomLine.bottom+40.0f, kDeviceWidth-20*2, 40.0f);
    logoutBtn.layer.masksToBounds = YES;
    logoutBtn.layer.cornerRadius = 4.0f;
    [logoutBtn setBackgroundColor:kRedColor];
    [logoutBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [logoutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    [logoutBtn addTarget:self action:@selector(logoutBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:logoutBtn];
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:Login_Status])
    {
        logoutBtn.hidden = NO;
    }
    else
    {
        logoutBtn.hidden = YES;
    }
}


- (void)logoutBtnAction
{
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:Login_Status];
    
    NSUserDefaults *userT = [NSUserDefaults standardUserDefaults];
    [userT removeObjectForKey:User_Privilege_Default];
    [userT synchronize];
    
    LoginViewController *loginVC = [[LoginViewController alloc] init];
    [self presentViewController:[[UINavigationController alloc] initWithRootViewController:loginVC] animated:YES completion:^{
        [self.navigationController popToRootViewControllerAnimated:NO];
        [kAPPDelegate.rootVC clickTabWithIndex:1];
    }];
    
    //NSDictionary *bodyDic = [NSDictionary dictionaryWithObjectsAndKeys:[[UserInfo getInstance] getUserID],@"UserID",[[UserInfo getInstance] getUseToken],@"UserToken", nil];
    //[[YMNetLib getInstance] connectWithAction:Logout_API method:@"POST" withContent:nil withBody:bodyDic withDelegate:self];
}

- (void)NetDoOverSuccess:(NSDictionary*)body
{
    if ([[YMNetDataUtil getSuccessState:body] intValue] == 1)
    {
        
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
